#coding: utf-8

# Copyright (c) P SOFTHOUSE. All rights reserved.

import maya.cmds as cmds  # pylint: disable=E0401
import maya.mel as mel
from PencilLineGuiUtils import *

"""
    "Authorize" Dialog
"""
def showAuthorizeDialog():
    launchPencilTool("SLSetting", isModal=True)
    mel.eval("pcl4license -reload")
    mel.eval('refreshEditorTemplates') # Command also exists as Python command, but it does not work!
    cmds.refresh()


def showOpenBetaDialog(mode=0):
    u"""
    オープンベータダイアログの表示
    mode=0  途中経過用
    mode=1  期限切れ用
    """
    cmds.layoutDialog(title="Pencil+ 4 Open Beta", ui=lambda : openBetaDialogUi(mode))


def openBetaDialogUi(mode):
    fixDialogSize()
    form = cmds.setParent(q=True)
    cmds.formLayout(form, e=True, width=400, height=20)

    if mode == 0:
        message = cmds.text(label=getLocalizedString("kOpenBetaInfoMiddle"))
    else:
        message = cmds.text(label=getLocalizedString("kOpenBetaInfoExpired"))
    url = cmds.text(label=  "<a href='https://www.psoft.co.jp/jp/product/pencil/maya/form/'>"\
                            "<span style='color:#ff007e;'>PSOFT Feedback Form</span>"\
                            "</a>"
                    , hyperlink=True)

    okButton = cmds.button(label="OK", c='maya.cmds.layoutDialog(dismiss="OK")')

    cmds.formLayout(form,
        edit=True,
        attachForm=
        [
         (message, "top", 30),
         (message, "left", 5),
         (message, "right", 5),
         (url, "left", 5),
         (url, "right", 5),
         (okButton, "left", 150),
         (okButton, "right", 150),
         (okButton, "bottom", 15)
        ],
        attachControl=
        [
         (url, "top", 20, message),
         (okButton, "top", 30, url),
        ]
        )

def removeOpenBetaOptionVar():
    cmds.optionVar(remove='pcl4OpenBetaHash')
    cmds.optionVar(remove='pcl4OpenBetaStartDate')
    cmds.optionVar(remove='pcl4OpenBetaAnnounceType')
    cmds.optionVar(remove='pcl4OpenBetaAnnounceFreq')
